module.exports = {
  cluster: {
    queryAll: params => {
      let conditionObj = {};
      for (let key in params) {
        conditionObj[key] = {
          in: params[key].in ? params[key].in : params[key]
        }
      }
      let s = `select id,
        name,
        description,
        status,
        DATE_FORMAT(crdt,'%Y-%m-%d %H:%i:%S') as crdt,
        DATE_FORMAT(mddt,'%Y-%m-%d %H:%i:%S') as mddt 
        from cluster where deleted = 0`;
      for (let key in conditionObj) {
        s += ` and ${key} in (${conditionObj[key].in.join(',')})`
      }
      return s;
    },
    query: params => `select
        id,
        name,
        description,
        status,
        DATE_FORMAT(crdt,'%Y-%m-%d %H:%i:%S') as crdt,
        DATE_FORMAT(mddt,'%Y-%m-%d %H:%i:%S') as mddt 
      from cluster where deleted = 0
      order by ${params.sort} ${params.direction}
      limit ${params.size}
      offset ${(params.page - 1) * params.size}`,
    count: _ => `select count(*) as total from cluster where deleted = 0`,
    delete: params => `update cluster set deleted = 1, deldt = now() where uuid = '${params.uuid}'`,
    expunge: params => `update cluster set recover = 1 where uuid = '${params.uuid}' and deleted = 1`
  },
  host: {
    query: params => `select
        uuid,
        name,
        description,
        status,
        DATE_FORMAT(crdt,'%Y-%m-%d %H:%i:%S') as crdt,
        DATE_FORMAT(mddt,'%Y-%m-%d %H:%i:%S') as mddt 
      from host where deleted = 0
      order by ${params.sort} ${params.direction}
      limit ${params.size}
      offset ${(params.page - 1) * params.size}`,
  }
};
